<include file="Public:header" />
<div style="boder:1px solid #ccc;margin:10px 10px 0px 10px;">
    <div style="border:1px solid #ccc;height:40px;padding:0 0 0 20px;line-height:40px;">
           站内链接管理
    </div>
    <form action="{:U('Websitelink/addWebsiteLink')}" method="post" enctype="multipart/form-data" onsubmit="return checkForm()">
    <div style="border:1px solid #ccc;height:auto;padding:5px 18px 5px 11px;margin-top:5px;"> 
    <table width="100%">
           <tr>
               <td colspan="2">
                   <input type="submit" name="save" value="添加" />
                   <input type="reset" value="重置" />
                   <input type="button" id="return" value="返回" />
               </td>
           </tr>
           <tr>
                <td align="right" width="150" style="border:1px solid #ccc">链接名称：</td>
                <td>
                    <input type="text" style="width:50%" id="link_name" name="link_name" value="" />&nbsp;<span id="error_name">链接的显示名称</span>
                </td>
           </tr>
           <tr>
                <td align="right" width="150" style="border:1px solid #ccc">链接地址：</td>
                <td>
                    <input type="text" style="width:50%" id="link_url" name="link_url" value="http://" />&nbsp;<span id="error_url">链接的连接地址</span>
                </td>
            </tr>
            <tr>
                <td align="right" width="150" style="border:1px solid #ccc">是否使用图片：</td>
                <td>
                    <input type="radio" id="check_1" name="ifUseImage" value="1" /> 是
                    <input type="radio" id="check_2" name="ifUseImage" value="0" checked /> 否
                </td>
            </tr>
            <tr id="link_imageSize"> 
                <td align="right" width="150" style="border:1px solid #ccc">图片大小：</td>
                <td valign="middle">
                    <input type="text" name="link_imageSize" id="imageSize" size="5"value="" />&nbsp;XP  <span id="error_imageSize">格式为<span style="color:red">*(宽)x(小写字母"x")*(高)</span>,不支持多张</span>
                </td>
            </tr>
            <tr id="link_image"> 
                <td align="right" width="150" style="border:1px solid #ccc">链接图片：</td>
                <td>
                    <input type="file" id="link_image" name="image" value="" />&nbsp;<span id="error_image">仅支持<span style="color:red">jpg,jpeg,png,gif</span>格式的图片!</span>
                </td>
            </tr>
            
    </table>
    </div>
    </form>
</div>
  </body>
  <script type="text/javascript">
      jq("#return").click(function(){
             location.href="{:U('WebsiteLink/index')}";        
      });
      jq("#check_1").click(function(){
             jq("#link_imageSize").show(); 
             jq("#link_image").show();        
      });
      jq("#check_2").click(function(){
              jq("#link_imageSize").hide(); 
              jq("#link_image").hide();     
      });

      jq("#link_imageSize").hide(); 
      jq("#link_image").hide();
      function checkForm(){
          var sta = 0;
          var link_name       = document.getElementById("link_name");
          var error_name      = document.getElementById("error_name");
          var link_url        = document.getElementById("link_url");
          var error_url       = document.getElementById("error_url");
          var check_1         = document.getElementById("check_1"); 
          var imageSize  = document.getElementById("imageSize");
          var error_imageSize = document.getElementById("error_imageSize");
          var image      = document.getElementById("image");
          var error_image     = document.getElementById("error_image");
          //alert(check_1.checked);return false;
          if(link_name.value == "" ){
              error_name.innerHTML = "<span style='color:red'>链接名称不能为空！</span>";
              return false;
          }else{
              error_name.innerHTML = "<span style='color:green'>链接名称已填写！</span>";
              sta += 1;
          } 
          if(link_url.value.length < 8 ){
              //alert(link_url.value.length);//return false;
              error_url.innerHTML  = "<span style='color:red'>请将链接地址填写完整！</span>";
              return false;
          }else{
              error_url.innerHTML = "<span style='color:green'>链接地址已填写！</span>";
              sta += 1;
          }
          if(check_1.checked == true){
              //alert(imageSize.value);return false;
              if(imageSize.value == ""){
                  error_imageSize.innerHTML = "<span style='color:red'>请设置图片大小！</span>";
                  return false;
              }else{
                  //return false
                  var val = imageSize.value;
                  var len = val.length;
                  var pos = val.indexOf("x");
                  //alert(len+" "+pos);return false;
                  var wid = val.substr(0,pos);
                  var hei = val.substr(pos+1,len);
                  //alert(wid+" "+hei);return false;
                  if(wid<=0){
                      error_imageSize.innerHTML = "<span style='color:red'>图片的<span style='font-size:20px'>宽</span>度不能小于零！格式为<span style='color:green'>(宽)x(小写字母'x')*(高)</span>,不支持多张</span>";
                         return false;
                  }
                  if(hei<=0){
                      error_imageSize.innerHTML = "<span style='color:red'>图片的<span style='font-size:20px'>高</span>度不能小于零！格式为<span style='color:green'>(宽)x(小写字母'x')*(高)</span>,不支持多张</span>";
                         return false;
                  }
                  if(wid>0 && hei>0){
                         error_imageSize.innerHTML = "<span style='color:green'>图片大小的格式设置正确！</span>";
                         sta += 1;
                  }
                  if(image.value == ""){
                         error_image.innerHTML = "<span style='color:red'>请选择一张上传图片！</span>";
                         return false;
                  }else{
                         error_image.innerHTML = "<span style='color:green'>上传图片已选择！</span>"; 
                         sta += 1;
                  }
                  if(sta == 4){
                      return true;
                  }else{
                      return false;
                  }
              }
              
              
          }
          
          if(sta == 2 && check_1.checked == false ){
                return true;
          }
      }
  </script>
</html>
